Fix: energy-saving mode stops RTMP stream by implementing it as a pure UI overlay#5
Draft
Fix: energy-saving mode stops RTMP stream by implementing it as a pure UI overlay#5
Conversation
…ream alive The energy-saving mode toggle was breaking the RTMP stream because any implementation that calls stopPreview() on the encoder while streaming closes the camera capture session — the video encoder loses its frame input and the stream fails. Fix: implement energy-saving entirely in the UI layer. - CameraPreview (SurfaceView) always stays in the Compose composition, so surfaceDestroyed / stopPreview is never triggered on the encoder. - A dark 0xFF111111 overlay composable is shown on top when energy-saving is active, hiding the camera feed visually without touching the encoder. - Toggling on/off any number of times is safe; the RTMP stream is completely unaffected. Changes: - StreamViewModel: add isEnergySavingEnabled StateFlow, toggleEnergySaving() method, and auto-reset to false on stream Idle/Stopped transitions. - StreamScreen: add energy-saving overlay (Layer 2 in the Box stack), add VisibilityOff/Visibility toggle button to the streaming control panel. Co-authored-by: alxayo <2588978+alxayo@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix RTMP stream stop issue in energy-saving mode
Fix: energy-saving mode stops RTMP stream by implementing it as a pure UI overlay
Mar 18, 2026
This was referenced Mar 19, 2026
This was referenced Mar 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Enabling energy-saving mode (hide preview, dim screen) was stopping the live RTMP stream. The cause: any code path that calls
stopPreview()while streaming closes the camera capture session — the encoder loses its frame input and the stream fails. Additionally,startPreview()always constructs a newRtmpCamera2instance, so re-enabling preview mid-stream would destroy the active streaming object.Fix
Energy-saving is implemented entirely in the UI layer. The encoder, camera, and RTMP connection are never touched.
StreamViewModel— addsisEnergySavingEnabled: StateFlow<Boolean>andtoggleEnergySaving(). Resets tofalseonIdle/Stoppedtransitions for a clean next session.StreamScreen—CameraPreview(SurfaceView) always stays in the Compose composition regardless of energy-saving state. Removing it would triggersurfaceDestroyed→detachPreviewSurface()→stopPreview(), breaking the stream. A near-black overlay (0xFF111111) is composited on top when active.Visibility/VisibilityOfftoggle button to the streaming control panel (visible only while streaming), following the existingMic/MicOfficon-shows-current-state convention.Toggling on/off any number of times during a live stream is safe.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
dl.google.com/usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.13-bin/5xuhj0ry160q40clulazy9h7d/gradle-8.13/lib/gradle-daemon-main-8.13.jar(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Created from VS Code.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.